package conf

import (
	"fmt"
	"github.com/BurntSushi/toml"
	"github.com/caarlos0/env/v6"
)

//如果配置映射成Config对象
//从Toml格式的的配置文件加载配置
func LoadConfigFromToml(filePath string) error {
	config :=NewDefaultConfig()
	_,err := toml.DecodeFile(filePath,config)
	if err !=nil{
		return fmt.Errorf("load config from file error ,path : %s,%s",filePath,err)
	}
	return loadGloabal()
} 

	
//从环境变量加载配置
func LoadConfigFromEnv() error {
	config =NewDefaultConfig() 
	err :=env.Parse(config)
	if err !=nil{
		return err
	}
	return loadGloabal()
}

	//加载全局实例
func loadGloabal() (err error){
	db ,err =config.MySQL.getDBConn()
		if err !=nil{
			return err
		}
	return 
}